﻿using Microsoft.Extensions.Hosting;
using MiniCap.Transport;

namespace MiniCap.Workers
{
    public class ConsumerService : BackgroundService
    {
        private readonly RabbitMqTransport _transport;

        public ConsumerService(RabbitMqTransport transport)
        {
            _transport = transport;
        }

        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            string topic = "TestTopic";

            _transport.Subscribe(topic, async message =>
            {
                Console.WriteLine($"[Consumer] Received message on topic '{topic}': {message}");
                await Task.CompletedTask;
            });

            return Task.CompletedTask;
        }
    }
}
